package com.gqb.aop;

import java.lang.reflect.Method;

public abstract class AbstractProxy implements Proxy {

	public void doProxy(ProxyChain proxyChain) {
		Class<?> clazz = proxyChain.getClass();
		Method method = proxyChain.getMethod();
		Object[] params = proxyChain.getArgs();
		begin();
		try {
			if (filter(clazz, method, params)) {
				before(clazz, method, params);
				proxyChain.doProxyChain();
				after(clazz, method, params);
			}
		} catch (Exception e) {
			e.printStackTrace();
			error(clazz, method, params);
		} finally {
			end();
		}

	}

	public void begin() {

	}

	public boolean filter(Class<?> clazz, Method method, Object[] params) {
		return true;
	}

	public void before(Class<?> clazz, Method method, Object[] params) {
	}

	public void after(Class<?> clazz, Method method, Object[] params) {
	}

	public void error(Class<?> clazz, Method method, Object[] params) {

	}

	public void end() {
	}
}
